home *** CD-ROM | disk | FTP | other *** search
- /* © 1988, Bowers Development Corp. */
- /* Dragging.c */
-
- #include "Globals.h"
- #include "ResourceDefs.h"
-
- #include "Dragging.h"
-
-
- /*----------*/
- short Abs (short x);
- short Abs (x)
- short x;
- {
- return ((x < 0) ? (-x) : (x));
- } /*Abs*/
-
- /*----------*/
- Boolean StartMove (startPt, constraint)
- Point *startPt;
- short *constraint;
- {
- #define slop 2
-
- Rect slopRect;
- Point mousePt;
-
- #define sP (*startPt)
- SetRect (&slopRect, sP.h, sP.v, sP.h + 1, sP.v + 1);
- #undef sP
-
- InsetRect (&slopRect, -slop, -slop);
-
- mousePt = *startPt;
- while (StillDown () && PtInRect (mousePt, &slopRect)) {
- GetMouse (&mousePt);
- }
-
- if (StillDown ()) {
- *constraint = noConstraint;
- if ((curEvent.modifiers & optionKey) != 0) {
- if (Abs (mousePt.h - (*startPt).h)
- > Abs (mousePt.v - (*startPt).v)) {
- *constraint = hAxisOnly;
- } else {
- *constraint = vAxisOnly;
- }
- }
- }
-
- *startPt = mousePt;
- if ((*startPt).h > (slopRect).right) { (*startPt).h = (slopRect).right; }
- if ((*startPt).h < (slopRect).left) { (*startPt).h = (slopRect).left - 1; }
- if ((*startPt).v > (slopRect).bottom) { (*startPt).v = (slopRect).bottom; }
- if ((*startPt).v < (slopRect).top) { (*startPt).v = (slopRect).top - 1; }
-
- return (StillDown ());
- } /*StartMove*/
-
- /*----------*/
- Boolean TrackMove (dragRgn,
- startPt,
- bounds,
- constraint,
- deltaH,
- deltaV,
- actionProc)
- RgnHandle dragRgn;
- Point startPt;
- Rect bounds;
- short constraint;
- short *deltaH;
- short *deltaV;
- DragProcPtr actionProc;
- {
- #undef slop
- #define slop 20
-
- Rect limitRect;
- Rect slopRect;
- long delta;
- register Rect *dragBBox;
-
- dragBBox = &(**dragRgn).rgnBBox;
- SetRect (&limitRect,
- bounds.left - dragBBox->left,
- bounds.top - dragBBox->top,
- bounds.right - dragBBox->right + 1,
- bounds.bottom - dragBBox->bottom + 1);
-
- OffsetRect (&limitRect, startPt.h, startPt.h);
- slopRect = limitRect;
- InsetRect (&slopRect, -slop, -slop);
-
- delta = DragGrayRgn (dragRgn, startPt, &limitRect,
- &slopRect, constraint, (ProcPtr) actionProc);
- *deltaV = HiWord (delta);
- *deltaH = LoWord (delta);
-
- if (( delta == 0)
- || (*deltaH == 0x8000)
- || (*deltaV == 0x8000)) {
- return (false);
- } else {
- return (true);
- }
- } /*TrackMove*/
-
- /*----------*/
- Boolean TrackRange (anchorPt, range)
- Point anchorPt;
- Rect *range;
- {
- PenState savePen;
- Point curPos;
- Point newPos;
- long lastTicks;
-
- GetPenState (&savePen);
- PenNormal ();
- PenMode (notPatXor);
- PenPat (gray);
-
- newPos = anchorPt;
- curPos = newPos;
- Pt2Rect (anchorPt, curPos, range);
- FrameRect (range); /*Draw*/
-
- lastTicks = 0;
- while (StillDown ()) {
- if (TickCount () >= lastTicks + 2) {
- GetMouse (&newPos);
- if (!EqualPt (newPos, curPos)) {
- FrameRect (range); /*Undraw*/
- curPos = newPos;
- Pt2Rect (anchorPt, curPos, range);
- FrameRect (range); /*Draw*/
- }
- lastTicks = TickCount ();
- }
- } /*while*/
-
- FrameRect (range); /*Undraw*/
-
- SetPenState (&savePen);
-
- return (!EmptyRect (range));
- } /*TrackRange*/
-
- /*----------*/
- void PinPt (Rect limitRect,
- Point *where);
- void PinPt (limitRect, where)
- Rect limitRect;
- Point *where;
- {
- #define lR limitRect
- if (where->v < lR.top) where->v = lR.top;
- if (where->h < lR.left) where->h = lR.left;
- if (where->v > lR.bottom) where->v = lR.bottom;
- if (where->h > lR.right) where->h = lR.right;
- #undef LR
- } /*PinPt*/
-
- /*----------*/
- Boolean TrackRect (sizeRect, limitRect, actionProc)
- Rect *sizeRect;
- Rect limitRect;
- DragProcPtr actionProc;
- {
- PenState savePen;
- Point curPos;
- Point newPos;
- Point offset;
- Rect slopRect;
- long lastTicks;
- long temp;
-
- #define InSlop PtInRect (botRight (sizeRect), &slopRect)
-
- GetPenState (&savePen);
- PenNormal ();
- PenMode (notPatXor);
- PenPat (gray);
-
- slopRect = limitRect;
- InsetRect (&slopRect, -20, -20);
-
- GetMouse (&curPos);
- temp = DeltaPoint (botRight (sizeRect), curPos);
- offset = *(Point *) &temp;
-
- FrameRect (sizeRect); /*Draw*/
-
- lastTicks = 0;
- while (StillDown ()) {
- if (TickCount () >= lastTicks + 2) {
- GetMouse (&newPos);
- if (!EqualPt (newPos, curPos)) {
- if (InSlop) {
- FrameRect (sizeRect); /*Undraw*/
- }
- curPos = newPos;
- AddPt (offset, &newPos);
- botRight (sizeRect) = newPos;
- if (InSlop) {
- PinPt (limitRect, &botRight (sizeRect));
- FrameRect (sizeRect); /*Draw*/
- }
- if (actionProc != nil) {
- CallPascal (actionProc);
- }
- }
- lastTicks = TickCount ();
- }
- } /*while*/
-
- if (InSlop) {
- FrameRect (sizeRect); /*Undraw*/
- }
-
- SetPenState (&savePen);
-
- return (InSlop);
-
- #undef InSlop
- } /*TrackRect*/
-
- /*----------*/
- void FrameLine (Rect sizeRect);
- void FrameLine (sizeRect)
- Rect sizeRect;
- {
- MoveTo (sizeRect.left, sizeRect.top);
- LineTo (sizeRect.right - 1, sizeRect.bottom - 1);
- } /*FrameLine*/
-
- /*----------*/
- Boolean TrackLine (sizeRect, limitRect, actionProc)
- Rect *sizeRect;
- Rect limitRect;
- DragProcPtr actionProc;
- {
- PenState savePen;
- Point curPos;
- Point newPos;
- Point Offset;
- Rect slopRect;
- long lastTicks;
- long temp;
-
- #define InSlop PtInRect (botRight (sizeRect), &slopRect)
-
- GetPenState (&savePen);
- PenNormal ();
- PenMode (notPatXor);
- PenPat (gray);
-
- slopRect = limitRect;
- InsetRect (&slopRect, -20, -20);
-
- GetMouse (&curPos);
- temp = DeltaPoint (botRight (sizeRect), curPos);
- Offset = *(Point *) &temp;
-
- FrameLine (*sizeRect); /*Draw*/
-
- lastTicks = 0;
- while (StillDown ()) {
- if (TickCount () >= lastTicks + 2) {
- GetMouse (&newPos);
- if (!EqualPt (newPos, curPos)) {
- if (InSlop) {
- FrameLine (*sizeRect); /*Undraw*/
- }
- curPos = newPos;
- AddPt (Offset, &newPos);
- botRight (sizeRect) = newPos;
- /* ?? constrain line to be horizontal or vertical ?? */
- /* With sizeRect do {
- /* if ((right - left) > (bottom - top)) {
- /* bottom = top + 1;
- /* } else {
- /* right = left + 1;
- /* }
- /* } /*with*/
- if (InSlop) {
- PinPt (limitRect, &botRight (sizeRect));
- FrameLine (*sizeRect); /*Draw*/
- }
- if (actionProc != nil) {
- CallPascal (actionProc);
- }
- }
- lastTicks = TickCount ();
- }
- } /*while*/
-
- if (InSlop) {
- FrameLine (*sizeRect); /*Undraw*/
- }
-
- SetPenState (&savePen);
-
- return (InSlop);
-
- #undef InSlop
- } /*TrackLine*/
-